package cn.fanyc.action.mq.kafka.consumer.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 消费者监听器
 *
 * @author Fanyc
 * @date 2020-06-29 14:23
 */
@Component
public class ConsumerListener {

    private Logger logger = LoggerFactory.getLogger(ConsumerListener.class);

    /**
     * topic1消费者
     *
     * @param record 收到的消息
     */
    @KafkaListener(topics = "${listener.topic}")
    public void onMessageTopic1(ConsumerRecord<?, ?> record) {
        String topic = record.topic();
        Object message = record.value();
        long offset = record.offset();
        int partition = record.partition();
        logger.info("【{}】消费者收到消息：{}，偏移={}，分区={}", topic, message, offset, partition);
    }

}
